#include "headfile.h"

int adjust_address = 0; // 初始地址

int menu()
{
	static uint8_t str_show = 0;
	if(str_show == 0)
	{
		LCD_ShowUint8(10, 10, 0,WHITE,BLACK,0);
		LCD_PutString(40, 10, " Car_Speed ",WHITE,BLACK,0);
		LCD_ShowUint8(10, 30, 1,WHITE,BLACK,0);
		LCD_PutString(40, 30, " Car_State ",WHITE,BLACK,0);
		LCD_ShowUint8(10, 140, 2,WHITE,BLACK,0);
		LCD_PutString(40, 140, " 2_3_Angle ",WHITE,BLACK,0);
		LCD_ShowUint8(10, 240, 2,WHITE,BLACK,0);
		LCD_PutString(40, 240, " Detha_Angle ",WHITE,BLACK,0);
		LCD_ShowUint8(10, 260, 3,WHITE,BLACK,0);
		LCD_PutString(40, 260, " 3_1_Angle ",WHITE,BLACK,0);
		LCD_ShowUint8(10, 280, 4,WHITE,BLACK,0);
		LCD_PutString(40, 280, " 3_5_Angle ",WHITE,BLACK,0);
		LCD_ShowUint8(10, 300, 5,WHITE,BLACK,0);
		LCD_PutString(40, 300, " Circle_count ",WHITE,BLACK,0);

		str_show = 1;
	}
	LCD_ShowUint8(190, 30, adjust_address,WHITE,BLACK,0);
	
	LCD_ShowInt16(150, 10, default_speed_target,WHITE,BLACK,0);
	
	LCD_ShowUint8(150, 30, Car_State,WHITE,BLACK,0);
	
	LCD_ShowInt16(150, 140, state_2_3_ideal_angle,WHITE,BLACK,0);
		
	LCD_ShowUint8(150, 240, Detha_angle,WHITE,BLACK,0);
	
	LCD_ShowInt16(150, 260, state_3_1_ideal_angle,WHITE,BLACK,0);
	
	LCD_ShowInt16(150, 280, state_3_5_ideal_angle,WHITE,BLACK,0);
	
	LCD_ShowUint8(150, 300, Circle_count,WHITE,BLACK,0);

	if(GET_KEY2 == 0)
		{
			adjust_address ++;
			if(adjust_address > 5)
				adjust_address = 0;
			while(GET_KEY2 == 0);
		}
		
		if(adjust_address == 0) // 显示当前选择
		{
			if(GET_KEY3 == 0)
			{
				default_speed_target = default_speed_target + 5;
				if(default_speed_target > 200)
					default_speed_target = 200;
				while(GET_KEY3 == 0);
			}
			if(GET_KEY4 == 0)
			{
				default_speed_target = default_speed_target - 5;
				if(default_speed_target < -200)
					default_speed_target = -200;
				while(GET_KEY4 == 0);
			}
		}
		else if(adjust_address == 1) // 显示当前选择
		{
			if(GET_KEY3 == 0)
			{
				Car_State ++;
				if(Car_State > 4)
					Car_State = 1;
				while(GET_KEY3 == 0);
			}
			if(GET_KEY4 == 0)
			{
				Car_State --;
				if(Car_State < 1)
					Car_State = 4;
				while(GET_KEY4 == 0);
			}
		}
		else if(adjust_address == 2) // 显示当前选择
		{
			if(Car_State == 2)
			{
				if(GET_KEY3 == 0)
				{
					state_2_3_ideal_angle ++;
					while(GET_KEY3 == 0);
				}
				if(GET_KEY4 == 0)
				{
					state_2_3_ideal_angle --;
					while(GET_KEY4 == 0);
				}
			}
			else if((Car_State == 3) || (Car_State == 4))
			{
				if(GET_KEY3 == 0)
				{
					Detha_angle ++;
					while(GET_KEY3 == 0);
				}
				if(GET_KEY4 == 0)
				{
					Detha_angle --;
					if(Detha_angle < 0)
						Detha_angle = 0;
					while(GET_KEY4 == 0);
				}
			}
		}
		else if(adjust_address == 3) // 显示当前选择
		{
			if(Car_State == 3 || Car_State == 4)
			{
				if(GET_KEY3 == 0)
				{
					state_3_1_ideal_angle ++;
					while(GET_KEY3 == 0);
				}
				if(GET_KEY4 == 0)
				{
					state_3_1_ideal_angle --;
					while(GET_KEY4 == 0);
				}
			}
		}
		else if(adjust_address == 4) // 显示当前选择
		{
			if(Car_State == 3 || Car_State == 4)
			{
				if(GET_KEY3 == 0)
				{
					state_3_5_ideal_angle ++;
					while(GET_KEY3 == 0);
				}
				if(GET_KEY4 == 0)
				{
					state_3_5_ideal_angle --;
					while(GET_KEY4 == 0);
				}
			}
		}
		else if(adjust_address == 5) // 显示当前选择
		{
			if(Car_State == 4)
			{
				if(GET_KEY3 == 0)
				{
					Circle_count ++;
					while(GET_KEY3 == 0);
				}
				if(GET_KEY4 == 0)
				{
					Circle_count --;
					if(Circle_count < 1)
						Circle_count = 1;
					while(GET_KEY4 == 0);
				}
			}
		}

	return 0;
}

/*
LCD_PutString(10, 20, " address ",WHITE,BLACK,0);	
		LCD_ShowUint8(150, 20, address,WHITE,BLACK,0);
		
		// -------------------- 第一层菜单 --------------------------------
		if(address == 1) // 显示当前选择
		{
			if(GET_KEY3 == 0)
			{
				Car_State ++;
				if(Car_State > 4)
					Car_State = 1;
				while(GET_KEY3 == 0);
			}
			LCD_PutString(10, 40, " Car_State ",WHITE,BLACK,0);	
			LCD_ShowUint8(150, 40, Car_State,WHITE,BLACK,0);
		}

		// -------------------- 第二层菜单 --------------------------------
		if(address == 2)
		{
			if(Car_State == 1) // 选择题目1
			{
				LCD_PutString(10, 60, " 1 Good Luck！ ",WHITE,BLACK,0);	
				LCD_ShowUint8(150, 60, 66,WHITE,BLACK,0);

				if(GET_KEY4 == 0) // ENTER键
				{
					floor_2 = 0;
					floor_1 = 0;
				}
			}
			else if(Car_State == 2) // 选择题目2
			{
				LCD_PutString(10, 60, " 2 Good Luck！ ",WHITE,BLACK,0);	
				LCD_ShowUint8(150, 60, 66,WHITE,BLACK,0);

				if(GET_KEY4 == 0) // ENTER键
				{
					return 0;
				}
			}
			else if(Car_State == 3) // 选择题目3
			{
				LCD_PutString(10, 40, " 3 Good Luck！ ",WHITE,BLACK,0);	
				LCD_ShowUint8(150, 40, 66,WHITE,BLACK,0);

				if(GET_KEY4 == 0) // ENTER键
				{
					return 0;
				}
			}
			else if(Car_State == 4) // 选择题目4
			{
				LCD_PutString(10, 40, " 4 Good Luck！ ",WHITE,BLACK,0);	
				LCD_ShowUint8(150, 40, 66,WHITE,BLACK,0);

				if(GET_KEY4 == 0) // ENTER键
				{
					return 0;
				}
			}
		}
 */